package com.guli.order.service.impl;

import com.guli.commonutils.bean.CourseWebVo;
import com.guli.commonutils.bean.UcenterMember;
import com.guli.order.bean.Order;
import com.guli.order.client.EduClient;
import com.guli.order.client.UcentClient;
import com.guli.order.mapper.OrderMapper;
import com.guli.order.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.order.utils.OrderNoUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-04-20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private EduClient eduClient;
    @Resource
    private UcentClient ucentClient;
    @Override
    public String saveOrder(String courseId, String memberIdByJwtToken) {
        //通过远程调用根据用户id获取用户信息
        UcenterMember member = ucentClient.getMemberByTokenToComment(memberIdByJwtToken);
        //通过远程调用获取课程信息
        CourseWebVo course = eduClient.getById2(courseId);
        //创建订单
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(course.getTitle());
        order.setCourseCover(course.getCover());
        order.setTeacherName("test");
        order.setTotalFee(course.getPrice());
        order.setMemberId(memberIdByJwtToken);
        order.setMobile(member.getMobile());
        order.setNickname(member.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
